package com.wc.fortnight_blue_bridge.Q231111.Q6282;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.Scanner;

/**
 * @Author congge
 * @Date 2023/11/11 19:30
 * @description
 * 鲜花之海
 * https://www.lanqiao.cn/problems/6282/learning/?contest_id=146
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        Main main = new Main();
        while (t-- > 0) {
            long n = sc.nextInt();
            long k = sc.nextLong();
            main.search(n, k);
        }
    }

    public void search(long n, long k) {
        long midRow = n * (n + 1) / 2;
        if (k <= midRow) {
            long left = 1;
            long right = n;
            long mid;
            while (left <= right) {
                mid = left + (right - left) / 2;
                long last = mid * (mid + 1) / 2;
                if (last >= k) {
                    right = mid - 1;
                } else {
                    left = mid + 1;
                }
            }
            k -= ((left - 1) * left / 2);
            long y = k;
            long x = left - k + 1;

            System.out.println(y + " " + x);
        } else {
            long left = 1;
            long right = n - 1;
            long mid;
            k -= midRow;
            while (left <= right) {
                mid = left + (right - left) / 2;
                long last = mid * (n - 1 + n - mid) / 2;
                if (last >= k) {
                    right = mid - 1;
                } else {
                    left = mid + 1;
                }
            }
            k -= (n - left + 1 + n - 1) * (left - 1) / 2;
            long y = left + 1 + k - 1;
            long x = n - k + 1;
            System.out.println(y + " " + x);
        }
    }

    static class Input {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

        public int nextInt() {
            try {
                in.nextToken();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return (int) in.nval;
        }
    }

}
